package com.ouyeel.wlxer.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ouyeel.wlxer.R;
import com.ouyeel.wlxer.bean.MenuItem;

import java.util.List;

/**
 * Created by rankaifeng on 2017/11/16.
 */

public class MenuItemAdapter extends BaseAdapter {
    private Context mContext;
    private List<MenuItem> menuItemList;
    private LayoutInflater inflater;
    public MenuItemAdapter(Context mContext, List<MenuItem> menuItemList) {
        this.mContext = mContext;
        this.menuItemList = menuItemList;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return menuItemList.size();
    }

    @Override
    public MenuItem getItem(int position) {
        return menuItemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        convertView = inflater.inflate(R.layout.gradview_item, null);
        RelativeLayout relMytask = convertView.findViewById(R.id.rel_mytask);
        ImageView imgGradviewItem = convertView.findViewById(R.id.img_gradview_item);
        TextView tvTtitle = convertView.findViewById(R.id.tv_mytask);
        MenuItem menuItem = getItem(position);

        relMytask.setBackgroundResource(menuItem.getBackgroundColor());
        imgGradviewItem.setImageResource(menuItem.getImgId());
        tvTtitle.setText(menuItem.getStrTitle());
        return convertView;
    }

}
